home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / p_man / cat3 / IPC::Open2.Z / IPC::Open2
Encoding:
Text File  |  1998-10-28  |  3.4 KB  |  133 lines

  1.  
  2.  
  3.  
  4.      IIIIPPPPCCCC::::::::OOOOppppeeeennnn2222((((3333))))   22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     IIIIPPPPCCCC::::::::OOOOppppeeeennnn2222((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       IPC::Open2, open2 - open a process for both reading and
  10.       writing
  11.  
  12.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.           use IPC::Open2;
  14.           $pid = open2(\*RDR, \*WTR, 'some cmd and args');
  15.         # or
  16.           $pid = open2(\*RDR, \*WTR, 'some', 'cmd',    'and', 'args');
  17.  
  18.  
  19.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  20.       The _o_p_e_n_2() function spawns the given    $cmd and connects $rdr
  21.       for reading and $wtr for writing.  It's what you think
  22.       should work when you try
  23.  
  24.           open(HANDLE, "|cmd args|");
  25.  
  26.       The write filehandle will have autoflush turned on.
  27.  
  28.       If $rdr is a string (that is,    a bareword filehandle rather
  29.       than a glob or a reference) and it begins with ">&", then
  30.       the child will send output directly to that file handle.  If
  31.       $wtr is a string that    begins with "<&", then WTR will    be
  32.       closed in the    parent,    and the    child will read    from it
  33.       directly.  In    both cases, there will be a _d_u_p(2) instead of
  34.       a _p_i_p_e(2) made.
  35.  
  36.       _o_p_e_n_2() returns the process ID of the    child process.    It
  37.       doesn't return on failure: it    just raises an exception
  38.       matching /^open2:/.
  39.  
  40.      WWWWAAAARRRRNNNNIIIINNNNGGGG
  41.       It will not create these file    handles    for you.  You have to
  42.       do this yourself.  So    don't pass it empty variables
  43.       expecting them to get    filled in for you.
  44.  
  45.       Additionally,    this is    very dangerous as you may block
  46.       forever.  It assumes it's going to talk to something like
  47.       bbbbcccc, both writing to it and reading from it.  This is
  48.       presumably safe because you "know" that commands like    bbbbcccc
  49.       will read a line at a    time and output    a line at a time.
  50.       Programs like    ssssoooorrrrtttt that read their entire input stream
  51.       first, however, are quite apt    to cause deadlock.
  52.  
  53.       The big problem with this approach is    that if    you don't have
  54.       control over source code being run in    the child process, you
  55.       can't    control    what it    does with pipe buffering.  Thus    you
  56.       can't    just open a pipe to cat    -v and continually read    and
  57.       write    a line from it.
  58.  
  59.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  60.  
  61.  
  62.  
  63.      PPPPaaaaggggeeee 1111                        ((((pppprrrriiiinnnntttteeeedddd 11110000////22223333////99998888))))
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      IIIIPPPPCCCC::::::::OOOOppppeeeennnn2222((((3333))))   22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     IIIIPPPPCCCC::::::::OOOOppppeeeennnn2222((((3333))))
  71.  
  72.  
  73.  
  74.       See the _I_P_C::_O_p_e_n_3 manpage for an alternative    that handles
  75.       STDERR as well.  This    function is really just    a wrapper
  76.       around _o_p_e_n_3().
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.